package org.hp.util;

import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class Utils {
    /**
     * 将对象转换成json返回页面
     */
    public static void returnJson(Object obj, HttpServletResponse response){
        String s = JSON.toJSONString(obj);
        PrintWriter pw = null;
        try {
            pw = response.getWriter();
            pw.write(s);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(pw!=null) {
                pw.close();
            }
        }
    }
}
